package com.zl.tby.vo;

import com.zl.tby.core.base.util.ToolsUtil;
import com.zl.tby.model.TbyUavRecord;
import lombok.Data;
import org.noear.solon.validation.annotation.Length;
import org.noear.solon.validation.annotation.NotBlank;
import org.noear.solon.validation.annotation.NotNull;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 无人机使用记录
 * @author changpeng
 * @version 1.0
 * @since 2024/8/19 19:17
 */
@Data
public class TbyUavRecordForm {
    private Long id;
    /**无人机id*/
    @NotNull(message = "无人机不能为空")
    private Long uavId;
    /**飞行里程*/
    @NotNull(message = "飞行里程不能为空")
    private BigDecimal flightDistance;
    /**飞行时长*/
    @NotNull(message = "飞行时长不能为空")
    private BigDecimal flightTime;
    /**使用时间*/
    @NotNull(message = "使用时间不能为空")
    private Date useDate;
    /**任务类型*/
    @NotNull(message = "任务类型不能为空")
    private String taskCode;
    /**无人机名称*/
    private String uavName;
    /**使用时间*/
    private String useDateFormat;

    public TbyUavRecord createEntity() {
        TbyUavRecord entity = new TbyUavRecord();
        entity.setUavId(this.getUavId());
        entity.setFlightDistance(this.getFlightDistance());
        entity.setFlightTime(this.getFlightTime());
        entity.setUseDate(this.getUseDate());
        entity.setTaskCode(this.getTaskCode());
        return entity;
    }

    public void updateEntity(TbyUavRecord entity) {
        entity.setUavId(this.getUavId());
        entity.setFlightDistance(this.getFlightDistance());
        entity.setFlightTime(this.getFlightTime());
        entity.setUseDate(this.getUseDate());
        entity.setTaskCode(this.getTaskCode());
    }

    public static TbyUavRecordForm recordConvert(TbyUavRecord entity, String navName) {
        return TbyUavRecordForm.recordConvert(entity, navName, "yyyy-MM-dd HH:mm");
    }

    /**
     * 数据转换
     * @param entity: 实体对象
     * @param navName：无人机名称
     * @param dateFormat：使用日期格式化
     * @return
     */
    public static TbyUavRecordForm recordConvert(TbyUavRecord entity, String navName, String dateFormat) {
        TbyUavRecordForm form = new TbyUavRecordForm();
        form.setId(entity.getId());
        form.setUavId(entity.getUavId());
        form.setUavName(navName);
        form.setFlightDistance(entity.getFlightDistance());
        form.setFlightTime(entity.getFlightTime());
        form.setUseDate(entity.getUseDate());
        form.setUseDateFormat(ToolsUtil.dateUtil2String(entity.getUseDate(), dateFormat));
        form.setTaskCode(entity.getTaskCode());
        return form;
    }
}
